package com.zhentao.controller;


import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.pojo.car.ChargeCarInfo;
import com.zhentao.service.ChargeCarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 桑田
 **/
@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    ChargeCarInfoService infoService;
    //车辆列表
    @PostMapping("/carList")
    public ResponseResult carList(){
        return ResponseResult.okResult(infoService.carList());
    }
//    查看当前车主的车
    @PostMapping("/ownerCar")
    public ResponseResult ownerCar(Integer userId){
        return ResponseResult.okResult(infoService.getByOwner(userId));
    }
//    新增车辆
    @PostMapping("/addCar")
    public ResponseResult addCar(ChargeCarInfo car){
        return ResponseResult.okResult(infoService.save(car));
    }
//    更新车辆信息
    @PostMapping("/updateCar")
    public ResponseResult updateCar(ChargeCarInfo car){
        return ResponseResult.okResult(infoService.updateById(car));
    }
//    开始充电(充到100%自动停止充电)
    @PostMapping("/startCharg")
    public ResponseResult startCharg(Integer id){
        return infoService.startCharg(id);
    }
//    停止充电（手动停止）
    @PostMapping("/stopCharg")
    public ResponseResult stopCharg(Integer id){
        return infoService.stopCharg(id);
    }
//    打开充电桩
    @GetMapping("/open")
    public ResponseResult open(){
        return infoService.open();
    }
    //支付账单
    @PostMapping("/payBill")
    public ResponseResult pay(Integer id){
        return infoService.payBill(id);
    }

}
